package cn.cjxy.day15employeemanagement.service.impl;

import cn.cjxy.day15employeemanagement.domain.Dept;
import cn.cjxy.day15employeemanagement.mapper.DeptMapper;
import cn.cjxy.day15employeemanagement.service.DeptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huangjie
 * @date 2025/10/21
 */
@Service
public class DeptServiceImpl implements DeptService {

    //调用mapper层方法   现在这里没有写逻辑    写完测试没有问题，再去写controller
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void addDept(Dept dept) {
        deptMapper.addDept(dept);
    }

    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateDept(dept);
    }

    @Override
    public void delDeptById(Long id) {
        deptMapper.delDeptById(id);
    }

    @Override
    public Dept selectById(Long id) {
        return deptMapper.selectById(id);
    }

    @Override
    public PageInfo<Dept> selectAllByPage(int pageNum, int pageSize) {
        //分页插件
        PageHelper.startPage(pageNum, pageSize);
        List<Dept> depts = deptMapper.selectAllDepts();
        PageInfo<Dept> deptPageInfo = new PageInfo<>(depts);
        return deptPageInfo;
    }

    @Override
    public int batchAddDepts(List<Dept> deptList) {
        return deptMapper.batchInsertDepts(deptList);
    }
}
